package com.train.common.model.event;

import lombok.Data;
import org.slf4j.MDC;

import java.time.LocalDateTime;

@Data
public class EvnetHeader {

    /**
     * 业务ID
     */
    private Long bizId;

    /**
     * 日志跟踪ID
     */
    private String logId;

    /**
     * 消息来源
     */
    private String messageSource;

    /**
     * 消息时间
     */
    private LocalDateTime messageTime;

    /**
     * 重试次数
     */
    private Integer retryCount;

    /**
     * 延迟级别[1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 15m 20m 30m 1h 2h]
     */
    private Integer delayLevel;

    public EvnetHeader() {}

    public EvnetHeader(Long bizId, String messageSource) {
        this(bizId, messageSource, null, null);
    }

    public EvnetHeader(Long bizId, String messageSource, Integer retryCount) {
        this(bizId, messageSource, retryCount, null);
    }

    public EvnetHeader(Long bizId, String messageSource, Integer retryCount, Integer delayLevel) {
        this.bizId = bizId;
        this.logId = MDC.get("LOG_ID");
        this.messageTime = LocalDateTime.now();
        if (retryCount == null || retryCount == 0) {
            retryCount = 3;
        }
        this.messageSource = messageSource;
        this.retryCount = retryCount;
        this.delayLevel = delayLevel;
    }
}
